import { UserConfigExport, ConfigEnv } from "vite";
// import { viteMockServe } from "vite-plugin-mock";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
// import styleImport from "vite-plugin-style-import";
// import { generateModifyVars } from "./build/generate/generateModifyVars";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";

function pathResolve(dir: string) {
  return resolve(process.cwd(), ".", dir);
}

export default ({ command }: ConfigEnv): UserConfigExport => {
  return {
    base: "/hire-manage-web/",
    server: {
      host: "0.0.0.0",
      port: 3002,
    },
    build: {
      minify: false,
      rollupOptions: {
        input: {
          main: pathResolve("index.html"),
        },
      },
    },
    resolve: {
      alias: [
        // /@/xxxx => src/xxxx
        {
          find: /\/@\//,
          replacement: pathResolve("src") + "/",
        },
        // /#/xxxx => types/xxxx
        {
          find: /\/#\//,
          replacement: pathResolve("types") + "/",
        },
        {
          find: "vue-i18n",
          replacement: "vue-i18n/dist/vue-i18n.cjs.js",
        },
      ],
    },
    css: {
      preprocessorOptions: {
        less: {
          // modifyVars: generateModifyVars(),
          javascriptEnabled: true,
          modifyVars: {
            hack: `true;@import (reference) "${resolve("src/style/config.less")}";`,
          },
        },
      },
    },
    plugins: [
      vue(),
      Components({
        dts: true,
        resolvers: [
          AntDesignVueResolver({
            importStyle: false,
          }),
        ],
        // exclude: [/[\\/]components[\\/]pages[\\/]/],
      }),
      // viteMockServe({
      //   // default
      //   mockPath: "mock",
      //   localEnabled: command === "serve",
      // }),
    ],
  };
};
